

package com.csun.cmny.provider.device.watch.entity;

import java.text.DecimalFormat;


    /// <summary>
    ///  上行关机数据包
    ///  无关联
    ///  Upside off data packet
    ///  Unrelated command
    /// </summary>
    public class C005
    {

        /// <summary>
        /// 数据起封包 @B#@ 
        /// Start Fixed value :@B#@ 
        /// </summary>
        public String HeadCode = "@B#@";
        /// <summary>
        /// 协议版本号
        /// Protocol version number
        /// </summary>
        public String Protocol = null;
        /// <summary>
        /// 功能代码识别
        /// Function code
        /// </summary>
        public final String FunCode = "005";
        /// <summary>
        /// 国际移动设备身份码
        /// International Mobile Equipment Identity
        /// </summary>
        public String IMEI  = null;
        /// <summary>
        /// 国际移动用户识别码
        /// International Mobile Subscriber Identification Number
        /// </summary>
        public String IMSI  = null;
        /// <summary>
        /// 剩余电量百分比（range:1-100）
        /// Percentage of residual electricity (range:1-100)
        /// </summary>
        public int Power = 0;
        /// <summary>
        /// 终端当前时间(年月日时分秒) yyyyMMddHHmmss
        /// The terminal current time ( format:yyyyMMddHHmmss)
        /// </summary>
        public String TerminalTime  = null;
        /// <summary>
        /// 当LbsType(地理位置类型)为 1 (GPS)  手环上传格式：纬度值|经度值
        /// When LbsType (geographical location type) was 1 (GPS) format:   latitude|longitude
        /// </summary>
        public String GpsString  = null;
        /// <summary>
        /// 当LbsType(地理位置类型)为 2 (基站)  手环上传格式：cell_id,lac,mnc,mcc,rssi|cell_id,lac,mnc,mcc,rssi|...
        /// When LbsType (geographic location type) was 2 (cell),  upload format: cell_id,lac,mnc,mcc,rssi|cell_id,lac,mnc,mcc,rssi|...
        /// </summary>
        public String CellString  = null;
        /// <summary>
        /// 当LbsType(地理位置类型)为 3 (WIFI+基站)  手环上传格式：1c:fa:56:b5,-61&1c:fa:56:b5,-61|cell_id,lac,mnc,mcc,rss&cell_id,lac,mnc,mcc,rss
        /// When LbsType (geographic location type) was 2 (wifi+cell),  upload format:  1c:fa:56:b5,-61&1c:fa:56:b5,-61|cell_id,lac,mnc,mcc,rss&cell_id,lac,mnc,mcc,rss
        /// </summary>
        public String WifiCellString  = null;
        /// <summary>
        /// 地理位置类型 1:GPS 定位位置  2:基站定位位置   3:WIFI+基站定位
        /// Location type 1:GPS location position 2: base station location location 3:WIFI+ base station location
        /// </summary>
        public int LbsType =0;
        /// <summary>
        /// 结尾封包 @E#@
        /// End packet @E#@
        /// </summary>
        public String FootCode = "@E#@";

        public C005(){}



        /// <summary>
        /// 初始化模型
        /// @B#@|01|005|111112222233333|8888888888888888|55|20160715150323|125.48276|37.615124|1|@E#@
        /// </summary>
        /// <param name="cmdStr">命令代码</param>
        public  C005(String cmdStr)
        {
        	String[] data = cmdStr.split("\\|");
            int dataLength = data.length;
            if (dataLength > 10 && "@B#@".equals(data[0]) && FunCode.equals(data[2]))
            {
                HeadCode = data[0];
                Protocol = data[1];
                IMEI = data[3];
                IMSI = data[4];
                Power = Integer.parseInt(data[5]);
                TerminalTime = data[6];
              
                LbsType = Integer.parseInt(data[dataLength - 2]);
                FootCode = data[dataLength - 1];  
                DecimalFormat df = new DecimalFormat("#.00000");
                
                //GPS数据
                if (LbsType == 1)
                {
                	String lat = df.format(Float.parseFloat(data[7]));
                	String lon =df.format(Float.parseFloat(data[8]));
                    GpsString = lat + "|" + lon;
                }
                //基站数据
                if (LbsType == 2)
                {
                    CellString = "";
                    for (int i = 7; i < dataLength - 2; i++)
                    {

                        if (i == dataLength - 3)
                        {
                            CellString += data[i];
                        }
                        else
                        {
                            CellString += data[i] + "|";
                        }

                    }

                }
                //wifi数据+基站数据
                if (LbsType == 3)
                {

                    WifiCellString = data[7] + "|" + data[8];
                }
            }

        }

        public  String ToString()
        {
        	String rString = HeadCode + "|";
            rString += Protocol + "|";
            rString += FunCode + "|";
            rString += IMEI + "|";
            rString += IMSI + "|";
            rString += Power + "|";
            rString += TerminalTime + "|";
            rString += GpsString + "|";
            rString += CellString + "|";
            rString += WifiCellString + "|";
            rString += LbsType + "|";
            rString += FootCode;
            return rString;
        }
    }




